/**
 * 
 */
package basicprocess;

import java.util.Hashtable;
import java.util.Vector;

import pool.tablename.Property_details;
import pool.tablename.Pool;


import utility.CapitalChar;
import utility.ConvertToLower;
import utility.Input;

import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;

/**
 * @author POOL
 *
 */
public class Inheritance implements Basicprocessinterface 
{
	DBManager database;
	Hashtable<Object, Object>Mastermap= new Hashtable<Object, Object>();
	Vector< Object>propertyVector = new Vector<Object>();
	String INHEITANCE ="inheritance";
	String REF="ref";
	GetIdName gid;
	Pool pool;
	Vector<Object>Inheritance = new Vector<Object>();
	basicprocess.inheritance.Inheritance inheritance;
	
	public Hashtable<Object, Object> getMasterHashtabel()
	{
		return Mastermap;
	}

	public Vector<Object> getpropertydetailsVector() 
	{
		return propertyVector;
	}

	public void setDbmanager(DBManager database) 
	{
		this.database = database;
		gid = new GetIdName(database);
		INHEITANCE = gid.getId(INHEITANCE);
	}


	
	public void setObject(Object obj) 
	{	
		pool = (Pool) obj;
	}

	public void getInsert() 
	{	
		Mastermap = pool.getHashtabel();
		propertyVector = pool.getpropertyVector();
		Hashtable<Object, Object> propertydetailstabel = new Hashtable<Object, Object>();
		for(int i=0;i<propertyVector.size();i++)
		{
			Property_details pd = (Property_details)propertyVector.get(i);
			propertydetailstabel.putAll((Hashtable<Object, Object>)  ConvertToLower.convertHashKey(pd.PropertyMap));
			System.out.println(propertydetailstabel.get("pid"));
			if(propertydetailstabel.get("pid").equals(INHEITANCE))
			{	
				propertydetailstabel.putAll((Hashtable<Object, Object>)  ConvertToLower.convertHashKey(pd.PropertyMap));
				
				try 
				{
					String typeofinheritances = gid.getItem(propertydetailstabel.get("ref").toString());
					Class c = Class.forName("basicprocess.inheritance."+CapitalChar.makeFirstCharCapital(typeofinheritances));
					inheritance = (basicprocess.inheritance.Inheritance) c.newInstance();
					inheritance.setDbmanager(database);
					inheritance.setobject(pool);	
					inheritance.getInsert();
					inheritance.getpropertydetailsVector();
				}
				catch (ClassNotFoundException e) 
				{
					e.printStackTrace();
				}
				catch (InstantiationException e) 
				{
					e.printStackTrace();
				}
				catch (Exception e) 
				{
					e.printStackTrace();
				}
			}
		}
	}

	public void getUpdate() 
	{	
		Mastermap = pool.getHashtabel();
		RecordSearch search =new RecordSearch(database);
		Hashtable<Object, Object>table = new Hashtable<Object, Object>();
		table.put("pid", INHEITANCE);
		table.put("pv", gid.getId(Mastermap.get("name").toString()));
		table.put("td", "null");
		String line [] = search.getArrayFromResultSet();
		try 
		{
			String splitline[] = line[0].split("\t");
			String typeofinheritances = gid.getItem(splitline[Column.ref_index-1]);					
			Class c = Class.forName("basicprocess.inheritance."+CapitalChar.makeFirstCharCapital(typeofinheritances));
			inheritance = (basicprocess.inheritance.Inheritance) c.newInstance();
			inheritance.setDbmanager(database);
			inheritance.setobject(pool);	
			inheritance.getUpdate();
			inheritance.getpropertydetailsVector();
		}
		catch (ClassNotFoundException e) 
		{
			e.printStackTrace();
		}
		catch (InstantiationException e) 
		{
			e.printStackTrace();
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		}
		

	public void processBasicprocess() {
		// TODO Auto-generated method stub
		
	}

	public Hashtable<Object, Object> getHashtable() {
		// TODO Auto-generated method stub
		return new Hashtable<Object, Object>();
	}
		
		
		
		
	
/*		for(int i=0;i<Inheritance.size();i++)
		{
			Inheritance inheritance = (Inheritance) Inheritance.get(i);
			inheritance.inheritance.getUpdate();
			inheritance.inheritance.getpropertydetailsVector();
		}*/
	/*public void processBasicprocess()
	{
		Mastermap = pool.getHashtabel();
		propertyVector = pool.getpropertyVector();
		Hashtable<Object, Object> propertydetailstabel = new Hashtable<Object, Object>();
		for(int i=0;i<propertyVector.size();i++)
		{
			PropertyDetails pd = (PropertyDetails)propertyVector.get(i);
			propertydetailstabel.putAll((Hashtable<Object, Object>)  ConvertToLower.convertHashKey(pd.PropertyMap));
			System.out.println(propertydetailstabel.get("pid"));
			if(propertydetailstabel.get("pid").equals(INHEITANCE))
			{	
				propertydetailstabel.putAll((Hashtable<Object, Object>)  ConvertToLower.convertHashKey(pd.PropertyMap));
				
				try 
				{
					String typeofinheritances = gid.getItem(propertydetailstabel.get("ref").toString());
					
					Class c = Class.forName("basicprocess.inheritance."+CapitalChar.makeFirstCharCapital(typeofinheritances));
					inheritance = (basicprocess.inheritance.Inheritance) c.newInstance();
					inheritance.setDbmanager(database);
					inheritance.setobject(pool);
					Inheritance.add(this);
					
					inheritance.processInheitance();
					inheritance.getpropertydetailsVector();
				catch (ClassNotFoundException e) 
				{
					e.printStackTrace();
				}
				catch (InstantiationException e) 
				{
					e.printStackTrace();
				}
				catch (Exception e) 
				{
					e.printStackTrace();
				}
			}
		}	
	}*/

	}
	

